package com.happe.foodeasy.winter.helper;

import com.happe.foodeasy.winter.conf.parser.WinterConfInformationParser;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * This class is the helper class that is used to help to parse configuration file.
 * Created by wubin on 2016-05-19.
 */
public class ConfigurationFilesParserHelper {
    public static Map<String, Object> properties2Map(Properties properties) {
        Map<String, Object> result = new HashMap<>();
        for (String oneP : properties.stringPropertyNames()) {
            result.put(oneP, properties.getProperty(oneP));
        }

        return result;
    }

    public static String getPathInRootClassPath(String filename) {
        URL url = WinterConfInformationParser.class.getClassLoader().getResource(filename);
        if (url != null) {
            return url.getPath();
        }
        throw new RuntimeException(filename + "配置文件无法找到");
    }
}
